home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Snippets / Toolbox / NoSound / main.c next >
Encoding:
C/C++ Source or Header  |  1992-07-15  |  3.1 KB  |  131 lines  |  [TEXT/KAHL]

  1. //    NoSound
  2. //    Created    3/1/92
  3. //    Faustino Forcén
  4.  
  5. #include "Finder.h"
  6. #include "shutdown.h"
  7. #include "script.h"
  8.  
  9. int    lee()
  10. {    
  11. int        elValor;
  12. FSSpec    spec;
  13. long    elCount;
  14. long    foundDir;
  15. short    vRef;
  16. OSErr    elError;
  17. Str255    nombredisco="\pNoSound.prefs";
  18. int        refNum;
  19.  
  20.     elError = FindFolder(kOnSystemDisk, 'pref', kDontCreateFolder,&vRef, &foundDir);
  21.             // another bendition from sys 7 or "How to find your way home in a drunky night"
  22.     if (elError == noErr)
  23.     {
  24.         FSMakeFSSpec(vRef, foundDir, nombredisco, &spec);    // the brand new calls from sys 7
  25.         elError = FSpOpenDF(&spec, fsRdWrPerm, &refNum);
  26.         if (elError != noErr)                                 // we failed…
  27.             return(3);                                        // default value
  28.         elCount = 2L;
  29.         FSRead(refNum, &elCount,&elValor);
  30.         FSClose(refNum);
  31.         if(elCount==0)                // file is empty
  32.             elValor=3;                // default value
  33.     }
  34.     else
  35.         elValor=3;
  36.     return(elValor);
  37. }
  38.  
  39. pascal void shut_down()
  40. {
  41.     int        refNum;
  42.     int        valor;    
  43.     SysPPtr    elPuntero;
  44.     FSSpec    spec;
  45.     long    elCount;
  46.     long    foundDir;
  47.     OSErr    elError;
  48.     short    vRef;
  49.     Str255    nombredisco;
  50.     
  51.     
  52.     // we haven´t globals at this time, so…
  53.     nombredisco[0]=13;
  54.     nombredisco[1]='N';
  55.     nombredisco[2]='o';
  56.     nombredisco[3]='S';
  57.     nombredisco[4]='o';
  58.     nombredisco[5]='u';
  59.     nombredisco[6]='n';
  60.     nombredisco[7]='d';
  61.     nombredisco[8]='.';
  62.     nombredisco[9]='p';
  63.     nombredisco[10]='r';
  64.     nombredisco[11]='e';
  65.     nombredisco[12]='f';
  66.     nombredisco[13]='s';
  67.     // yes, is really dirty, but it works
  68.  
  69.     InitUtil();                    // from the PRAM calls
  70.     elPuntero=GetSysPPtr();
  71.     valor = ((elPuntero->volClik & 0x0700) >> 8);
  72.     elError = FindFolder(kOnSystemDisk, 'pref', kDontCreateFolder, &vRef, &foundDir);
  73.     if (elError == noErr)
  74.     {
  75.         FSMakeFSSpec(vRef, foundDir, nombredisco, &spec);
  76.         elError = FSpOpenDF(&spec, fsRdWrPerm, &refNum);
  77.         if (elError == fnfErr)             // this is also your first time, baby?
  78.         {
  79.             FSpCreate(&spec, 'SARA', 'VOL ', smSystemScript);    
  80.                 // yes, my daughter calls SARA, how you guess it?
  81.             FSpOpenDF(&spec, fsRdWrPerm, &refNum);
  82.         }
  83.         elCount = 2L;
  84.         FSWrite(refNum, &elCount, &valor);
  85.         FSClose(refNum);
  86.     }
  87.         // here´s the real stuff, when we change the vol
  88.     elPuntero->volClik = (elPuntero->volClik & 0xf8ff) + (1 << 8);
  89.     WriteParam();
  90. }
  91.  
  92. void main(void)
  93. {
  94.     long size;
  95.     Ptr puntero,otro, temp;
  96.     char buffer[4];
  97.     int    refNum;
  98.     int    volumen;
  99.     SysPPtr    elPuntero;
  100.     
  101.     volumen=lee();    // we want to get the original volume, stored somewhere
  102.     InitUtil();
  103.     elPuntero=GetSysPPtr();
  104.         // we put the vol to the original value
  105.         // in the worst case (no file, some error) it will be 3 (default value)
  106.     elPuntero->volClik = (elPuntero->volClik & 0xf8ff) + (volumen << 8);
  107.     WriteParam();
  108.         // now tell the Mac that we changed its mind
  109.     SetSoundVol(volumen);
  110.     
  111.         // now began the install process
  112.     size = (long) ((Ptr) ApplLimit - (Ptr) ApplZone);
  113.     puntero = NewPtrSysClear(size);
  114.     if (puntero) 
  115.     {
  116.         temp = (Ptr) shut_down;
  117.         buffer[0] = *(temp+2);
  118.         buffer[1] = *(temp+3);
  119.         buffer[2] = *(temp+4);
  120.         buffer[3] = *(temp+5);
  121.         BlockMove(ApplZone,puntero,size);
  122.         otro = (Ptr) (long) puntero + (*(long *)buffer - (long) ApplZone);
  123.         ShutDwnInstall((ProcPtr)otro, sdRestartOrPower + sdOnUnmount + sdOnDrivers);
  124.     }
  125.     ExitToShell();
  126.     // we need to assure that our proc is linked with the app
  127.     shut_down();
  128. }
  129.  
  130. // eof
  131.